﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace ZMHWindowsService
{
    public partial class MyFirstService : ServiceBase
    {
        string logPath;
        public MyFirstService()
        {
            InitializeComponent();
            logPath = @"D:\MyFirstService.log";
        }
        protected override void OnStart(string[] args)
        {
            using (FileStream stream = new FileStream(logPath, FileMode.Append))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.WriteLine($"{DateTime.Now},Service has Started！");
                }
            }
        }
        protected override void OnStop()
        {
            using (FileStream stream = new FileStream(logPath, FileMode.Append))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.WriteLine($"{DateTime.Now},Service has Stoped！");
                }
            }
        }
    }
}
